package com.hivekion.system.controller;

import com.hivekion.common.annotation.AutoLog;
import com.hivekion.common.entity.TreeNode;
import com.hivekion.common.enums.OperationTypeEnum;
import com.hivekion.common.exception.BusinessException;
import com.hivekion.system.domain.vo.*;
import com.hivekion.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/menu")
public class SysMenuController {

      @Autowired
      ISysMenuService menuService;

      @GetMapping("/getInfo")
      public SysMenuModelVo getInfo(String menuId) {
	    return menuService.getInfo(menuId);
      }

      @GetMapping("/getTreeSelect")
      public List<TreeNode> getTreeSelect() {
	    return menuService.getTreeSelect();
      }

      @GetMapping("/getList")
      public List<SysMenuViewVo> getList() {
	    return menuService.getList();
      }

      @PostMapping("/add")
      @PreAuthorize("@Permission.hasPermi('pro:sys:menu:add')")
      @AutoLog(value = "新增菜单", operationType = OperationTypeEnum.INSERT, module = "系统管理/菜单管理")
      public boolean add(@RequestBody SysMenuCreateInputVo inputVo) {
	    return menuService.create(inputVo);
      }

      @PutMapping("/edit")
      @PreAuthorize("@Permission.hasPermi('pro:sys:menu:edit')")
      @AutoLog(value = "更新菜单信息", operationType = OperationTypeEnum.UPDATE, module = "系统管理/菜单管理")
      public boolean update(@RequestBody SysMenuUpdateInputVo inputVo) {
	    if (inputVo.getId().equals(inputVo.getParentId())) {
		  throw new BusinessException(500, "禁止选择当前菜单为父级菜单");
	    }
	    return menuService.update(inputVo);
      }

      @DeleteMapping("/remove")
      @PreAuthorize("@Permission.hasPermi('pro:sys:menu:remove')")
      @AutoLog(value = "删除菜单", operationType = OperationTypeEnum.DELETE, module = "系统管理/菜单管理")
      public boolean delete(String menuId) {
	    return menuService.delete(menuId);
      }

      @GetMapping("/getMenuPermission")
      public List<SysMenuPermissionVo> getMenuPermission() {
	    return menuService.getMenuPermission();
      }
}
